//验证码控制层,控制层用于前端交互

package controller

import (
	"admin-go-api/api/service"
	"admin-go-api/common/result"
	"encoding/json"
	"fmt"
	"github.com/gin-gonic/gin"
)

// @Summary 验证码接口
// @Produce json
// @Description 验证码接口
// @Success 200 {object} result.Result
// @router /api/captcha [get]
func Captcha(c *gin.Context) {
	id, base64Image, _ := service.CaptMake()
	result.Success(c, map[string]interface{}{"idKey": id, "image": base64Image})
}

// @Summary 行为验证码接口
// @Produce json
// @Description 行为验证码接口
// @Success 200 {object} result.Result
// @router /api/captcha/slide [get]
func CaptchaSide(c *gin.Context) {
	//id, base64Image, _ := service.CaptMake()
	str := service.CaptSideMake()
	var data map[string]interface{}
	err := json.Unmarshal([]byte(str), &data)
	if err != nil {
		fmt.Println("Error:", err)
		return
	}
	result.Success(c, data)
	//result.Success(c, map[string]interface{}{"idKey": id, "image": base64Image})
}
